import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import cart from '@/components/cart'
import item from '@/components/item'
import detail from '@/components/detail'
import mytest from '@/components/mytest'
import test from '@/components/test'
import zuoye from '@/components/zuoye'
import register from '@/components/register'
import login from '@/components/login'
import myprofile from '@/components/myprofile'
import kaoshi_register from '@/components/kaoshi_register'
import kao_login from '@/components/kao_login'
import addpics from '@/components/addpics'
import picslist from '@/components/picslist'
import updatepics from '@/components/updatepics'
import addgoods from '@/components/addgoods'
import editgoods from '@/components/editgoods'
import kaoshi_goodslist from '@/components/kaoshi_goodslist'
import kaoshi4 from '@/components/kaoshi4'
import search from '@/components/search'


















Vue.use(Router)

var routes = [
        {
          path:'/',
          name:'index',
          component:index
        },
        {
          path:'/cart',
          name:'cart',
          component:cart
        },
        {
          path:'/item',
          name:'item',
          component:item
        },
        {
          path:'/detail',
          name:'detail',
          component:detail
        },
        {
          path:'/mytest',
          name:'mytest',
          component:mytest
        },
        {
          path:'/test',
          name:'test',
          component:test
        },
        {
          path:'/zuoye',
          name:'zuoye',
          component:zuoye
        },
        {
          path:'/register',
          name:'register',
          component:register
        },
        {
          path:'/login',
          name:'login',
          component:login
        },
        //拦截器的使用
        {
          path:'/myprofile',
          name:'myprofile',
          component:myprofile,
          beforeEnter:(to,from,next) =>{
            //判断用户是否登录
            if(localStorage.getItem("username")){
              console.log('已登录');
              next();
            }else{
             
              next('/login') 
            }

          }
        },
        {
          path:'/kaoshi_register',
          name:'kaoshi_register',
          component:kaoshi_register
        },
        {
          path:'/kao_login',
          name:'kao_login',
          component:kao_login
        },
        //幻灯片
        {
          path:'/addpics',
          name:'addpics',
          component:addpics
        },
        {
          path:'/picslist',
          name:'picslist',
          component:picslist
        },
        {
          path:'/updatepics',
          name:'updatepics',
          component:updatepics
        },
        {
          path:'/addgoods',
          name:'addgoods',
          component:addgoods
        },
        {
          path:'/editgoods',
          name:'editgoods',
          component:editgoods
        },
        {
          path:'/goodslist',
          name:'kaoshi_goodslist',
          component:kaoshi_goodslist
        },
        {
          path:'/kaoshi4',
          name:'kaoshi4',
          component:kaoshi4
        },
        {
          path:'/search',
          name:'search',
          component:search
        }
        
        
        
]

export default new Router({
  routes:routes,
  mode:'history'   /*hash*/
})
